package com.test.down.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;

import com.google.gson.Gson;
import com.test.down.beans.TestLiveResult;

import java.io.InputStream;

public class PlayResource {

    public static TestLiveResult result;

    public static TestLiveResult getLiveData(Context context){
        if(result!=null) return result;
        try {
            AssetManager manager=context.getAssets();
            InputStream inputStream=manager.open("liveJson.json");
            StringBuffer buffer=new StringBuffer();
            byte[] bytes=new byte[1024];
            int length=0;
            while ((length=inputStream.read(bytes))!=-1){
                buffer.append(new String(bytes,0,length));
            }
            inputStream.reset();
            inputStream.close();
            String json=buffer.toString();
            Log.d("liveJson",json);
            result=new Gson().fromJson(json,TestLiveResult.class);
            return result;
        }catch (Exception e){
            return null;
        }
    }
}
